#include "gui_gloab.h"
#include "gui_func.h"

#define TITLE_WIN_SIZE       20

//按键控制
LV_EVENT_CB_DECLARE(imgbtn1_event_handler)
{
    switch (e)
    {
    case LV_EVENT_CLICKED://轻点
        break;
    case LV_EVENT_RELEASED://按压
        break;
    case LV_EVENT_PRESSED://松开
  //      env_set.cur_page = SW_CTRL_PAGE;
        break;
    case LV_EVENT_LONG_PRESSED://长按

        break;
    default:break;
    }
}
//按键控制
LV_EVENT_CB_DECLARE(imgbtn2_event_handler)
{
    switch (e)
    {
    case LV_EVENT_CLICKED://轻点
        break;
    case LV_EVENT_RELEASED://按压
        break;
    case LV_EVENT_PRESSED://松开
        
        break;
    case LV_EVENT_LONG_PRESSED://长按

        break;
    default:break;
    }
}



static void notice_board(lv_obj_t* parent)
{
    static lv_style_t time_style;
    //设置容器风格
    lv_style_init(&env_set.page_style);
    lv_style_set_radius(&env_set.page_style, LV_STATE_DEFAULT, 0);//设置页面圆角度数
    lv_style_set_bg_opa(&env_set.page_style, LV_STATE_DEFAULT, LV_OPA_TRANSP);//设置为透明
    // lv_style_set_bg_color(&env_set.page_style, LV_STATE_DEFAULT, LV_COLOR_WHITE);//设置页面底色
    lv_style_set_border_opa(&env_set.page_style, LV_STATE_FOCUSED, LV_OPA_TRANSP);//设置为透明
    //   lv_style_set_border_color(&env_set.page_style, LV_STATE_FOCUSED, LV_COLOR_WHITE);//页面聚焦边线色
    lv_style_set_border_opa(&env_set.page_style, LV_STATE_DEFAULT, LV_OPA_TRANSP);//设置为透明
    //   lv_style_set_border_color(&env_set.page_style, LV_STATE_DEFAULT, LV_COLOR_WHITE);//页面默认边线色
    lv_obj_t* cont = lv_cont_create(parent, NULL); //创建容器
    lv_obj_set_size(cont, LV_HOR_RES_MAX, TITLE_WIN_SIZE);//设置大小
    lv_obj_align(cont, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0);//左上角对齐
    lv_obj_add_style(cont, LV_PAGE_PART_BG, &env_set.page_style);//添加风格
    /*Create a label on the page*/

    lv_style_init(&time_style);
    lv_style_set_text_opa(&time_style, LV_STATE_DEFAULT, LV_OPA_COVER);//设置为透明
    lv_style_set_text_color(&time_style, LV_STATE_DEFAULT, LV_COLOR_WHITE);//设置页面底色

    lv_obj_t* label = lv_label_create(cont, NULL);
    lv_obj_align(label, cont, LV_ALIGN_IN_TOP_MID, 0, 0);//居中对齐
    lv_obj_add_style(label, LV_LABEL_PART_MAIN, &time_style);//添加风格
    lv_label_set_text(label, "12:23");
  
}

static void First_Page_Create(lv_obj_t* parent)
{
    static lv_style_t style;
    lv_style_init(&style);//对象风格初始化
    lv_style_set_image_recolor_opa(&style, LV_STATE_PRESSED, LV_OPA_30);//设置按下时的背景色深
    lv_style_set_image_recolor(&style, LV_STATE_PRESSED, LV_COLOR_GRAY);//设置按下时的背景色
 
    lv_obj_t* imgbtn1 = lv_imgbtn_create(parent, NULL);//创建图片按键
    lv_imgbtn_set_src(imgbtn1, LV_BTN_STATE_PRESSED, "0");//按下&H_PIC_0
    lv_imgbtn_set_src(imgbtn1, LV_BTN_STATE_RELEASED, "0");//抬起
    lv_obj_align(imgbtn1, NULL, LV_ALIGN_IN_TOP_LEFT, 30, 25);//左上角对齐
    lv_obj_set_event_cb(imgbtn1, imgbtn1_event_handler);//设置按钮回调
    lv_obj_add_style(imgbtn1, LV_IMGBTN_PART_MAIN, &style);//对象添加风格

    lv_obj_t* imgbtn2 = lv_imgbtn_create(parent, NULL);//创建图片按键
    lv_imgbtn_set_src(imgbtn2, LV_BTN_STATE_PRESSED, "1");//按下
    lv_imgbtn_set_src(imgbtn2, LV_BTN_STATE_RELEASED, "1");//抬起
    lv_obj_align(imgbtn2, NULL, LV_ALIGN_IN_TOP_LEFT, 150, 25);//左上角对齐
    lv_obj_set_event_cb(imgbtn2, imgbtn2_event_handler);//设置按钮回调
    lv_obj_add_style(imgbtn2, LV_IMGBTN_PART_MAIN, &style);//对象添加风格

//    lv_obj_set_drag(img3,true);//使能移动
}

static void Second_Page_Create(lv_obj_t* parent)
{
    static lv_style_t style;
    lv_style_init(&style);//对象风格初始化
    lv_style_set_image_recolor_opa(&style, LV_STATE_PRESSED, LV_OPA_30);//设置按下时的背景色深
    lv_style_set_image_recolor(&style, LV_STATE_PRESSED, LV_COLOR_GRAY);//设置按下时的背景色

    lv_obj_t* img1 = lv_imgbtn_create(parent, NULL);//创建图片按键
    lv_imgbtn_set_src(img1, LV_BTN_STATE_PRESSED, "0");//按下
    lv_imgbtn_set_src(img1, LV_BTN_STATE_RELEASED, "0");//抬起
    lv_obj_align(img1, NULL, LV_ALIGN_IN_TOP_LEFT, 30, 25);//左上角对齐
    lv_obj_set_event_cb(img1, imgbtn2_event_handler);//设置按钮回调
    lv_obj_add_style(img1, LV_IMGBTN_PART_MAIN, &style);//对象添加风格
}
static void action_task_cb(lv_task_t* t)
{
    lv_obj_t* img = t->user_data;
    lv_gif_restart(img);
}
//菜单页
void Home_Page_Create(void)
{
    /*Create a Tab view object*/
    lv_obj_t* tabview;

    lv_obj_t* bg_img = lv_gif_create_from_file(lv_scr_act(), "image/back.gif");
    lv_task_create(action_task_cb, 9000, LV_TASK_PRIO_HIGH, bg_img);

#if 0
    lv_obj_t* bg_img = lv_img_create(lv_scr_act(), NULL);//创建一个图像对象
    lv_img_set_src(bg_img, "0");//设置图片源
    lv_obj_align(bg_img, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0);//对齐
#endif

    lv_style_init(&env_set.page_style);//初始化风格
    lv_style_set_bg_opa(&env_set.page_style, LV_STATE_DEFAULT, LV_OPA_TRANSP);//设置背景为透明

    tabview = lv_tabview_create(lv_scr_act(), NULL);//创建一个tabview
    lv_obj_set_size(tabview, LV_HOR_RES_MAX, LV_VER_RES_MAX);//设置大小
    lv_obj_align(tabview, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0);//对齐
    lv_tabview_set_btns_pos(tabview, LV_TABVIEW_TAB_POS_NONE);//不显示btns
    lv_obj_add_style(tabview, LV_PAGE_PART_BG, &env_set.page_style);//添加风格

    lv_obj_t* tab1 = lv_tabview_add_tab(tabview, "Tab 1");//创建第一页
    lv_obj_t* tab2 = lv_tabview_add_tab(tabview, "Tab 2");//创建第二页
    notice_board(tabview);//创建通知栏
    First_Page_Create(tab1);//第一页
    Second_Page_Create(tab2);//第二页
}
